package com.sun.umbrella.controller.filterchains;

import com.sun.core.web.result.Result;
import com.sun.umbrella.domain.query.FilterChainsQuery;
import com.sun.umbrella.domain.vo.FilterChainsSaveVO;
import com.sun.umbrella.domain.vo.FilterChainsUpdateVO;
import com.sun.umbrella.domain.vo.FilterChainsVO;
import com.sun.umbrella.service.shiro.filter.resources.FilterChainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Jay
 * @version v1.0
 * @description 请添加类描述
 * @date 2018-04-27 17:42
 */

@Controller
@RequestMapping("/pc/filter")
public class FilterChainsController {


    @Autowired
    private FilterChainService filterChainService;


    /**
     * 分页查询配置资源列表
     *
     * @param filterChainsQuery
     * @param pageable
     * @return
     */
    @RequestMapping("/queryFilterChainsList")
    @ResponseBody
    public Result<Page<FilterChainsVO>> queryFilterChainsList(FilterChainsQuery filterChainsQuery
            , @PageableDefault(page = 1, size = 20, sort = "sys_id,idx_show", direction = Sort.Direction.ASC) Pageable pageable) {
        // 查询
        return Result.wrapSuccessfulResult(filterChainService.queryFilterChainsList(filterChainsQuery, pageable));
    }

    /**
     * 根据id删除资源列表
     *
     * @param id
     * @param sysId
     * @return
     */
    @RequestMapping("/deleteFilterChain")
    @ResponseBody
    public Result<Boolean> deleteFilterChain(Integer id, Integer sysId) {
        // 删除记录
        return Result.wrapSuccessfulResult(filterChainService.deleteFilterChain(id, sysId));
    }


    /**
     * 新增配置资源
     *
     * @param filterChainsSaveVO
     * @return
     */
    @RequestMapping("/saveFilterChain")
    @ResponseBody
    public Result<Boolean> saveFilterChain(FilterChainsSaveVO filterChainsSaveVO) {
        // 删除记录
        return Result.wrapSuccessfulResult(filterChainService.saveFilterChain(filterChainsSaveVO));

    }


    /**
     * 修改启用 禁用 状态
     *
     * @param id
     * @param enabledState
     * @return
     */
    @RequestMapping("/updateFilterEnable")
    @ResponseBody
    public Result<Boolean> updateFilterEnable(Integer id, Integer enabledState) {
        // 删除记录
        return Result.wrapSuccessfulResult(filterChainService.updateFilterEnable(id,enabledState));

    }


    /**
     * 修改过滤器配置资源
     *
     * @param filterChainsUpdateVO
     * @return
     */
    @RequestMapping("/updateFilterChain")
    @ResponseBody
    public Result<Boolean> updateFilterChain(FilterChainsUpdateVO filterChainsUpdateVO) {
        // 删除记录
        return Result.wrapSuccessfulResult(filterChainService.updateFilterChain(filterChainsUpdateVO));

    }

}
